package com.yifeng.repo.base.api;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by daibing on 2021/3/11.
 */
public class DateRange {

    private Date start;

    private Date end;

    public DateRange() {
    }

    public DateRange(Date start, Date end) {
        this.start = start;
        this.end = end;
    }

    public DateRange(Date time, int rangeMinutes, boolean reverse) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(time);
        ca.add(Calendar.MINUTE, reverse ? -rangeMinutes : rangeMinutes);
        this.start = reverse ? ca.getTime() : time;
        this.end = reverse ? time : ca.getTime();
    }

    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }

    @Override
    public String toString() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        return sdf.format(start) + " - " + sdf.format(end);
    }
}
